package com.upstairstechnology.oi.determination;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Required;

/**
 * Loaded properties for use by determination strategies.
 * 
 * @author Jeff Jensen
 */
public class DeterminationStrategyConfigurationCommand {

    /** SCM program to run, may include absolute or relative path as needed. */
    private String program;

    /**
     * SCM program arguments needed to determine outstanding integrations with
     * branchspecs.
     */
    private List<String> programArgumentsBranchspec;

    /**
     * SCM program arguments needed to determine outstanding integrations with
     * source target pairs.
     */
    private List<String> programArgumentsSourceTarget;

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    /**
     * Get the SCM program name, and may include an absolute or relative path as
     * needed.
     * 
     * @return The SCM program.
     */
    public String getProgram() {
        return program;
    }

    /**
     * Set the SCM program name, and include an absolute or relative path as
     * needed.
     * 
     * @param prg
     *            The SCM program; include an absolute or relative path as
     *            needed.
     */
    @Required
    public void setProgram(String prg) {
        this.program = prg;
    }

    /**
     * Get the SCM program arguments needed to determine outstanding
     * integrations with branchspecs.
     * 
     * @return The SCM program arguments needed to determine outstanding
     *         integrations with branchspecs.
     */
    public List<String> getProgramArgumentsBranchspecList() {
        return programArgumentsBranchspec;
    }

    /**
     * Get the branchspec program arguments in a string array format.
     * 
     * @return String array of the branchspec program arguments.
     */
    public String[] getProgramArgumentsBranchspec() {
        return programArgumentsBranchspec
                .toArray(new String[programArgumentsBranchspec.size()]);
    }

    /**
     * Set the SCM program arguments needed to determine outstanding
     * integrations with branchspecs.
     * 
     * @param args
     *            The SCM program arguments needed to determine outstanding
     *            integrations with branchspecs.
     */
    @Required
    public void setProgramArgumentsBranchspec(String[] args) {
        final String[] trimmedArgs = StringUtils.stripAll(args);
        this.programArgumentsBranchspec = Arrays.asList(trimmedArgs);
    }

    /**
     * Get the SCM program arguments needed to determine outstanding
     * integrations with source target pairs.
     * 
     * @return The SCM program arguments needed to determine outstanding
     *         integrations with source target pairs.
     */
    public List<String> getProgramArgumentsSourceTargetList() {
        return programArgumentsSourceTarget;
    }

    /**
     * Get the source target pair program arguments in a string array format.
     * 
     * @return String array of the source target pair program arguments.
     */
    public String[] getProgramArgumentsSourceTarget() {
        return programArgumentsSourceTarget
                .toArray(new String[programArgumentsSourceTarget.size()]);
    }

    /**
     * Set the SCM program arguments needed to determine outstanding
     * integrations with source target pairs.
     * 
     * @param args
     *            The SCM program arguments needed to determine outstanding
     *            integrations with source target pairs.
     */
    @Required
    public void setProgramArgumentsSourceTarget(String[] args) {
        final String[] trimmedArgs = StringUtils.stripAll(args);
        this.programArgumentsSourceTarget = Arrays.asList(trimmedArgs);
    }
}
